package com.brillilab.service.job.inventory;

import com.brillilab.domain.enums.hardware.LockOperationEnum;
import com.brillilab.domain.po.hardware.LockOperation;
import com.brillilab.service.core.hardware.ILockOperationService;
import com.brillilab.service.core.inventory.IInventoryDeleteRecordService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class InventoryDeleteJob implements Job {

    @Resource
    private IInventoryDeleteRecordService inventoryDeleteRecordService;
    @Resource
    private ILockOperationService lockOperationService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //获取参数
        JobDataMap map=context.getJobDetail().getJobDataMap();
        List<Long> recordIds= (ArrayList) map.get("recordIds");
        Long operateId=(Long) map.get("operateId");
        //删除记录
        if(recordIds!=null && recordIds.size()>0){
            inventoryDeleteRecordService.deleteByIds(recordIds);
        }
        //设置锁状态关闭
        if(operateId!=null){
            LockOperation operation = lockOperationService.selectById(operateId);
            if(operation!=null){
                operation.setOperate(LockOperationEnum.LOCK.getValue());
                lockOperationService.update(operation);
            }
        }
    }
}
